package com.babble.user.controller;

import com.babble.user.service.IUserService;
import com.babble.user.service.MailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.hibernate.validator.constraints.Email;
import org.springblade.common.exception.MsgException;
import org.springblade.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("mailController")
@Api(value = "邮箱模块(Controller)", tags = "邮箱接口")
public class MailController {
	IUserService userService;
	MailService mailService;
	@ApiOperation(value = "发送邮箱验证")
	@PostMapping("/user-mailSend")
	public R userMailSend(@Email(message = "格式必须为邮箱") @RequestParam("email") String email) throws MsgException {
		Integer integer = mailService.sendCode(email);
		if(integer!=0){
			return R.fail(integer.toString());
		}
		return R.success("发送成功");
	}
	@ApiOperation(value = "验证码邮箱验证")
	@PostMapping("/user-mailV")
	public R userMailV(@Min(000000) @Max(999999) @RequestParam("code") String code) throws MsgException {
		mailService.maillBind(code);
		return R.success("绑定成功");
	}



}
